import { ref } from "vue"
import logo from "@src/assets/logo.svg";
import logoPro from "@src/assets/logo2.svg";

const logoType = import.meta.env.VITE_APP_LOGO
const logoImg = logoType === 'pro' ? logoPro : logo

export const useApp = () => {
  const logoImageUrl = ref<string>(new URL(logoImg, import.meta.url).href)

  const currentTabName = ref('')

  const init = () => {
    const targetNode = document?.querySelector('.el-col-24')
    const observer = new MutationObserver(function logChanges() {
      currentTabName.value = targetNode?.querySelector('.el-breadcrumb__inner')?.textContent || ''
    })
    if(!targetNode) return console.error('监听tab 失败')
    observer.observe(targetNode, {childList:true, subtree:true})
  }

  return {
    logoImageUrl,
    currentTabName,

    init
  }
}